package com.company.modelo.service;

import java.util.List;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

import com.company.modelo.Entity.AccountEntity;
import com.company.modelo.dao.AccountDao;
import com.company.modelo.dao.AccountDaoImpl;



@Service
public class AccountServiceImpl implements AccountService {
	
	private static final Logger logger = Logger.getLogger(AccountServiceImpl.class);
	
	 @Autowired
	 private AccountDao accountdao;
	
	public AccountEntity getAccountDetails(String accountNumber) {
		logger.info("Llamada al metodo getAccountDetails con parametro accountNumber="+accountNumber);
		System.out.println("paso por servicio");		 
		 return accountdao.getAccountDetails(accountNumber);			 
		 
	}

	public List<AccountEntity> AccountFinAll() {
		try {
			return accountdao.findAll();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return null;
		}
		
	}

	public void DeleteAccount(Integer id) throws Exception {
		accountdao.delete(accountdao.findById(id));
		
	}

	public void SaveAccountAdd(AccountEntity obj) {	
		Integer result = null;
		try {
			result = accountdao.save(obj);
			///System.out.println("id grabado " + obj.getId());
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		
	}

	public void UpdateAccount(AccountEntity obj) {		 
		 try {			
			accountdao.saveOrUpdate(obj);			
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}

	public AccountEntity findById(Integer id) {
		try {
			return accountdao.findById(id);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return null;
		}
	}


}
